package LeetCode.month02.day32;

import com.sun.source.tree.ArrayAccessTree;

import java.util.Arrays;

public class No85 {
    public static void main(String[] args) {
        System.out.println(maximalRectangle(new char[][]{
                {'1','0','1','0','0'},
                {'1','0','1','1','1'},
                {'1','1','1','1','1'},
                {'1','0','0','1','0'},
        }));
    }
    public static int maximalRectangle(char[][] matrix) {
        int m = matrix.length;
        int n = matrix[0].length;
        int area = 0;
//        for (char[] chars : matrix) {
//            System.out.println(Arrays.toString(chars));
//        }
//        System.out.println();
        for (int top = 0; top < m; top++) {
            int[] arr = new int[n];
            for (int bottom = top; bottom < m; bottom++) {
                int h = bottom-top+1;
                int last = -1;
                for (int i = 0; i < n; i++) {
                    arr[i]+=matrix[bottom][i]-'0';
                    if(arr[i]!=h){
                        last = i;
                    }
//                    System.out.println("h = " + h);
                    area = Math.max((i-last)*h,area);
                }
//                System.out.println(Arrays.toString(arr));
//                System.out.println("area = " + area);
            }
//            System.out.println();
        }
        return area;
    }
}
